//
//  BaseTabBarViewController.m
//  TSDemo
//
//  Created by 汪小芳 on 2018/7/3.
//  Copyright © 2018年 WF. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "BaseNaviViewController.h"

@interface BaseTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    [UITabBar appearance].translucent = NO;
    [self setChildrenControllers];
}
- (void)setChildrenControllers{
    
    [self setupChildVc:[[NSClassFromString(kFirstViewController) alloc] init] title:NSLocalizedString(@"tb_home", nil) image:kTab_first1 selectedImage:kTab_first2];
    [self setupChildVc:[[NSClassFromString(kSecondViewController) alloc] init] title:NSLocalizedString(@"tb_work", nil) image:kTab_second1 selectedImage:kTab_second2];
    [self setupChildVc:[[NSClassFromString(kThirdViewController) alloc] init] title:NSLocalizedString(@"tb_mine", nil) image:kTab_third1 selectedImage:kTab_third2];

}

/**
 * 添加一个子控制器
 * @param title 文字
 * @param image 图片
 * @param selectedImage 选中时的图片
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    BaseNaviViewController *nav = [[BaseNaviViewController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    UIImage *img = IMAGE(image);
    UIImage *selectedImg = IMAGE(selectedImage);
    UITabBarItem *item = [[UITabBarItem alloc] init];
    item.title = title;
    NSDictionary *dictinfo = [NSDictionary dictionaryWithObject:[UIColor grayColor] forKey:NSForegroundColorAttributeName];
    NSDictionary *dictinfo2 = [NSDictionary dictionaryWithObject:RGBHex(0xe54b4b) forKey:NSForegroundColorAttributeName];
    [item setTitleTextAttributes:dictinfo forState:UIControlStateNormal];
    [item setTitleTextAttributes:dictinfo2 forState:UIControlStateSelected];
    [item setImage:[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item setSelectedImage:[selectedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item setTitlePositionAdjustment:UIOffsetMake(0, -3)];
    nav.tabBarItem = item;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
